<?php
include '../config/mysql.php';

//用户登录
if(!empty($_POST['type']) && $_POST['type'] == 'login'){
    $name = $_POST['name'];
    $password = $_POST['password'];
    $sql="SELECT * FROM admin WHERE  username = '{$name}' AND password = '{$password}'";
    //echo $sql;exit;
    if($pdo->query($sql)){
        $_SESSION['id'] = 1;
        success('index.php','登录成功');
    }else{
        error('login.php','登录失败');
    }
}

//用户退出登录
if(!empty($_GET['type']) && $_GET['type'] == 'logout'){
    unset( $_SESSION['id']);
    success('login.php','退出登录成功');

}

//添加用户
if(!empty($_POST['typec']) && $_POST['typec'] == 'adduser'){
    unset($_POST['typec']);
    $res = addsql('user',$_POST);
    if($res){
        success('userlist.php','添加成功');
    }else{
        error('useradd.php','添加失败');
    }
}

//修改用户 信息
if(!empty($_POST['type']) && $_POST['type'] == 'edituser'){
    $id = $_POST['id'];
    unset($_POST['id']);
    unset($_POST['type']);
    $res = update('user',$_POST,' where id = '.$id);
    if($res){
        success('userlist.php','修改成功');
    }else{
        error('userlist.php','修改失败');
    }

}



//删除用户
if(!empty($_GET['type']) && $_GET['type'] == 'userdel'){
    $id = $_GET['id'];
    $res = del('user',$id);
    if($res){
        success('userlist.php','删除成功');
    }else{
        error('userlist.php','删除失败');
    }
}



